/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.ember.ezsp.structure;

import java.util.HashMap;
import java.util.Map;

/**
 * Class to implement the Ember Enumeration <b>EmberExtendedSecurityBitmask</b>.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public enum EmberExtendedSecurityBitmask {
    /**
     * Default unknown value
     */
    UNKNOWN(-1),

    /**
     * If this bit is set, we set the 'key token data' field in the Initial Security Bitmask to 0 (No
     * Preconfig Key token), otherwise we leave the field as it is.
     */
    EMBER_PRECONFIG_KEY_NOT_VALID(0x0001),

    /**
     * This denotes whether a joiner node (router or end-device) uses a Global Link Key or a Unique
     * Link Key.
     */
    EMBER_JOINER_GLOBAL_LINK_KEY(0x0010),

    /**
     * This denotes whether the device's outgoing frame counter is allowed to be reset during
     * forming or joining. If flag is set, the outgoing frame counter is not allowed to be reset. If
     * flag is not set, the frame counter is allowed to be reset.
     */
    EMBER_EXT_NO_FRAME_COUNTER_RESET(0x0020),

    /**
     * This denotes whether a router node should discard or accept network Leave Commands.
     */
    EMBER_NWK_LEAVE_REQUEST_NOT_ALLOWED(0x0100);

    /**
     * A mapping between the integer code and its corresponding type to
     * facilitate lookup by code.
     */
    private static Map<Integer, EmberExtendedSecurityBitmask> codeMapping;

    private int key;

    static {
        codeMapping = new HashMap<Integer, EmberExtendedSecurityBitmask>();
        for (EmberExtendedSecurityBitmask s : values()) {
            codeMapping.put(s.key, s);
        }
    }

    private EmberExtendedSecurityBitmask(int key) {
        this.key = key;
    }

    /**
     * Lookup function based on the EmberStatus type code. Returns null if the
     * code does not exist.
     *
     * @param code the code to lookup
     * @return enumeration value of the alarm type.
     */
    public static EmberExtendedSecurityBitmask getEmberExtendedSecurityBitmask(int code) {
        if (codeMapping.get(code) == null) {
            return UNKNOWN;
        }

        return codeMapping.get(code);
    }

    /**
     * Returns the EZSP protocol defined value for this enumeration.
     *
     * @return the EZSP protocol key
     */
    public int getKey() {
        return key;
    }
}
